package com.ibeeking.gmc.global.api.feign.fallback;

import com.ibeeking.gmc.global.api.feign.GlobalMsgBaseCodeFeignClient;
import com.ibeeking.gmc.global.api.common.query.MsgBaseCodeFeignQuery;
import com.ibeeking.found.common.entity.MsgBaseCodeDTO;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;


/**
 * 降级工场
 *
 * @Author ibeeking
 * @date 2019/1/18
 */
@Component
public class GlobalMsgBaseCodeFeignFallbackFactory implements FallbackFactory<GlobalMsgBaseCodeFeignClient> {
    @Override
    public GlobalMsgBaseCodeFeignClient create(Throwable throwable) {
        return new GlobalMsgBaseCodeFeignClient() {
            @Override
            public ResponseResult<List<MsgBaseCodeDTO>> queryMsgBaseInfoList(MsgBaseCodeFeignQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂,查询消息基本信息列表失败。" + throwable.getMessage(), Collections.emptyList());
            }

            @Override
            public ResponseResult<MsgBaseCodeDTO> queryMsgBaseCodeDtoById(Long id) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂,查询消息基本信息失败。" + throwable.getMessage(), null);
            }

            @Override
            public ResponseResult<MsgBaseCodeDTO> queryMsgBaseCodeDtoByCode(String code) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂,查询消息基本信息失败。" + throwable.getMessage(), null);
            }
        };
    }
}
